/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package saa.dao;

import java.io.Serializable;
import java.util.List;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import saa.dominio.Curso;
import saa.dominio.usuario.Aluno;

/**
 *
 * @author lobao
 */
@Stateless
@LocalBean
public class CursoDAO implements Serializable {

    public CursoDAO() {
        super();
    }

    @PersistenceContext(unitName = "SAAPU")
    private EntityManager em;

    public List<Curso> listar() {
        try {
            return em
                    .createNamedQuery("Cursos", Curso.class)
                    .getResultList();
        } catch (Exception e) {
            return null;
        }
    }

    public Curso buscar(long cursoId) {
        try {
            return em
                    .find(Curso.class, cursoId);
        } catch (Exception e) {
            return null;
        }
    }

    public boolean adicionar(Curso curso) {
        try {
            em.persist(curso);
            return true;
        } catch (Exception e) {
            return false;
        }
    }

}
